package com.controller;

import com.bean.dto.Dto;
import com.bean.entity.Specifications;
import com.service.SpecificationsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("sp")
public class SpecificationsController {
    //自动注入
    @Autowired
    SpecificationsService specificationsService;

    @RequestMapping("queryAll")
    public Dto queryAll(Specifications specifications){
        //查询
        System.out.println(">>> 查询材料具体信息");
        List<Specifications> all = specificationsService.queryAll(specifications);
        return new Dto("0","查询信息！",all,"成功！");
    }

    @RequestMapping("save")
    public Dto save(Specifications specifications){
        //添加
        System.out.println(">>> 添加材料具体信息");

        try {
            specificationsService.save(specifications);
            return new Dto("0","新增成功!",null,"成功!");
        } catch (Exception e) {
            e.printStackTrace();
            return new Dto("0","新增失败!",null,"失败!");
        }
    }
    @RequestMapping("remove")
    public Dto remove(Specifications specifications){
        //删除
        System.out.println(">>> 删除材料具体信息");

        try {
            specificationsService.remove(specifications);
            return new Dto("0","删除成功!",null,"成功!");
        } catch (Exception e) {
            e.printStackTrace();
            return new Dto("0","删除失败!",null,"失败!");
        }
    }
    @RequestMapping("modify")
    public Dto modify(Specifications specifications){
        //删除
        System.out.println(">>> 修改材料具体信息");

        try {
            specificationsService.modify(specifications);
            return new Dto("0","修改成功!",null,"成功!");
        } catch (Exception e) {
            e.printStackTrace();
            return new Dto("0","修改失败!",null,"失败!");
        }
    }
}
